package com.njdf.servlet;

import com.njdf.entity.People;
import com.njdf.service.UserService;
import com.njdf.service.serviceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");
        String name=request.getParameter("name");
        UserService userService =new UserServiceImpl();
        Boolean ls= userService.delete(name);
        if(ls){
            System.out.println("成功");
            List<People> peoples=new ArrayList<>();
            peoples= userService.queryAll();
            request.setAttribute("peoples",peoples);
            request.getRequestDispatcher("/success.jsp").forward(request,response);
        }else{
            System.out.println("删除失败");
        }
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
